
// pages/user/work_detail/work_detail.js
const innerAudioContext = wx.createInnerAudioContext()
const urls = require('../../../utils/url.js').urls;
const http = require('../../../utils/url.js').http
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showView1: false,
    showView2: false,
    showView3:false,
    bl : false,
    num: 0,//后端给的分数,显示相应的星星
    one_1: '',
    two_1: '',

    lb:'',
    zt: '',
    xq: '',
    ypdz:'',
    gdrq: '',
    xm: '',
    zj: '',
    sj: '',
    gh: '',
    wcrq: '',
    gzyy: '',
    nc: '',
    tx: '../../../image/mrtx.png',
    nm: '0',
    pj: '',

    bl:false,
    time:0,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    showView1: (options.showView == "true" ? true : false)
    showView2: (options.showView == "true" ? true : false)
    showView3: (options.showView == "true" ? true : false)
    var that = this
    
  //  先判断工单在什么状态
    if (wx.getStorageSync('gdzt')==3){
        that.setData({
          showView3:true,
          showView2: true,
        })
    }
    else if (wx.getStorageSync('gdzt') == 2) {
      that.setData({
        showView2: true,
        showView3: false
      })
    }
    else{
      that.setData({
        showView2: false,
        showView3: false
      })
    }
    
    



    
    var param = {
      id: wx.getStorageSync('gdid')
    };
    http(urls.ordersDetails, param,function(res){
      console.log(res.data)

      that.setData({
        lb:res.data.lb,
        zt:res.data.zt,
        xq:res.data.describe,
        ypdz: res.data.voice_path,
        gdrq: res.data.create_time,
        xm:res.data.yhm,
        zj:res.data.zjh,
        sj:res.data.phone,
        wcrq: res.data.complete_time,
        gzyy: res.data.cause,
        num: parseInt(res.data.xj),
        nc:res.data.pjr,
        pj:res.data.ms,
        nm: res.data.isnm,
        time:res.data.yyms

      })
      console.log(parseInt(res.data.xj))
      //:展示后台给的评分
      that.setData({
        one_1: that.data.num,
        two_1: 5 - that.data.num
      })
      if(that.data.yydz==''){
        that.setData({
          showView1: false
        })
      }else{
        that.setData({
          showView1: true
        })
      }
    })

    var params = {
      openid: app.globalData.openid   
    };
    http(urls.details, params, function (res) {
      console.log(res.data)
      if (that.data.nm==1){
         that.setData({
           tx: res.data.avatarurl,

         })
       }

    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
   //播放声音
  play: function () {
    if (this.data.bl == false) {
      this.setData({
        bl: true
      })
    } else {
      this.setData({
        bl: false
      })
    }

    innerAudioContext.onError((res) => {　　　　　　 // 播放音频失败的回调
    })
    console.log("录音地址:" + this.data.ypdz)
    innerAudioContext.src = urls.bases+'upload/'+this.data.ypdz; // 这里可以是录音的临时路径
    if (this.data.bl == true) {

      innerAudioContext.play();
    } else {
      innerAudioContext.stop();
      innerAudioContext.pause();
    }
    innerAudioContext.onEnded(() => {
      this.setData({
        bl: false
      })
    })

  },
})